<template>
    <div class="select-form">
        <h3>插入表单</h3>
        <div class="options">
            <cube-scroll direction="horizontal">
                <div class="children"
                     v-for="(item,index) in options"
                     :key="item.value"
                     @click="clickOption(index)"
                     >
                    {{item.text}}
                </div>
            </cube-scroll>
        </div>
    </div>
</template>

<script>
export default {
    name: "select-form",
    data() {
        return {
            // 可插入的表单组件
            options: [
                {text: '普通文本', value: 'text'},
                {text: '多行文本', value: 'textarea'},
                {text: '手机号', value: 'phone'},
                {text: '单选', value: 'radio'},
                {text: '多选', value: 'select'},
                {text: '行政区域', value: 'area'}
            ],
            // 要插入的表单组件下标
            index: 0
        }
    },
    methods: {
        /**
         * 点击插入表单组件
         */
        clickOption(index) {
            this.index = index
            let dialog = this.$createDialog({
                type: 'prompt',
                title: '请输入表单名字',
                prompt: {
                    value: '',
                    placeholder: '请输入表单名字'
                },
                onConfirm: (e, value) => {
                    let data = {
                        type: this.options[index].value,
                        label: value
                    }
                    dialog.remove()
                    this.$emit("confirm",data)
                },
                zIndex: 1000
            })
            dialog.show()
        }
    }
}
</script>

<style scoped lang="less">
    @import "@/theme.less";
    .select-form{
        height: 40px;
        box-sizing: border-box;
        h3{
            width: 70px;
            text-align: center;
            height: 40px;
            line-height: 40px;
            border-right: 1px solid #ccc;
            float:left;
            box-sizing: border-box;
        }
        .options{
            float: left;
            width: 290px;
            height: 40px;
            padding:5px 0 0 5px;
            box-sizing: border-box;
            white-space: nowrap;
            .children{
                display: inline-block;
                margin-right: 10px;
                height: 30px;
                line-height: 30px;
                padding:0 10px;
                border: 1px solid @main-color1;
                border-radius: 15px;
                box-sizing: border-box;
            }
        }
    }
</style>

<style lang="stylus">
    .select-form .cube-scroll-content
        display: inline-block
</style>